package com.tpp.baseProvider.client;

import com.tpp.baseProvider.mapper.ImageMapper;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.tpp.comm.client.ImageClient;
import com.tpp.comm.pojo.TpImage;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

@RestController
public class ImageClientImpl implements ImageClient {

    @Resource
    private ImageMapper imageMapper;

    @Override
    public TpImage findImage(Integer targetId, Integer category, Integer type) {
        List<TpImage> tpImages = imageMapper.selectList(new LambdaQueryWrapper<TpImage>().
                eq(TpImage::getTargetId, targetId).
                eq(TpImage::getCategory, category).
                eq(TpImage::getType, type));
        TpImage tpImage = null;
        if(tpImages.isEmpty()){
            tpImage = new TpImage();
            tpImage.setImgUrl("https://img.alicdn.com/bao/uploaded/https://img.alicdn.com/imgextra/i3/2251059038/O1CN01O5SRRu2GdSGMIvYHq_!!2251059038.png");
        }else{
            tpImage=tpImages.get(0);
        }
        return tpImage;
    }
}
